//C13:ep13_2.c: copy file.
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    FILE *fr, *fw;
    char ch;
    char readfile[15];
    char writefile[15];

    printf("Enter the readfile name:\n");
    scanf("%s", readfile);
    printf("Enter the writefile name:\n");
    scanf("%s", writefile);
   
    if((fr = fopen(readfile, "r")) == NULL)
    {
        fprintf(stderr, "can not open readfile\n");
        exit(0);
    }

    if((fw = fopen(writefile, "w")) == NULL)
    {
        fprintf(stderr, "can not open writefile\n");
        exit(0);
    }

    while(!feof(fr))
    {
        fputc(fgetc(fr), fw);
    }

    fclose(fr);
    fclose(fw);
    exit(0);
}
